//封装request
//当前待处理请求数
let ajaxTimes = 0;
//加载中提示
export const request = (params) => {
  ajaxTimes ++;
  wx.showLoading({
    title: '加载中...',
    mask: true
  })

  const baseUrl = 'http://localhost:8080';

  return new Promise((resolve, reject) => {
    wx.request({
      ...params,
      url: baseUrl + params.url,
      success: (result) => {
        resolve(result.data);
      },
      fail: (err) => {
        reject(err);
      },
      //所有请求都结束时关闭加载中提示
      complete: () => {
        ajaxTimes --;
        if(ajaxTimes === 0){
          wx.hideLoading();
        }
      }
    })
  })
}